package br.kanban.view.mb;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;

import br.kanban.core.busines.RelatorioBO;

@Named
@ConversationScoped
public class RelatorioMB implements Serializable{

	private static final long serialVersionUID = 1L;

	@Inject
	private RelatorioBO relatorioBO;

	@Inject
	private Conversation conversation;
	
	private CartesianChartModel chart; 

	private List<Object[]> lista;

	private Date dataInicio, dataFim;
	
	@PostConstruct
	public void init(){
		if (conversation.isTransient()) conversation.begin();
	}
	
	public void gerarRelatorioTarefasFinalizada(){
		 lista = relatorioBO.relatorioTarefasFinalizada(dataInicio, dataFim);
		
		chart = new CartesianChartModel();
		for (Object[] object : lista) {
			ChartSeries serie = new ChartSeries();  
	        serie.setLabel("Tarefas Finalizadas");  
	        serie.set( (String) object[1], (Number) object[0] );  

	        chart.addSeries(serie);
		}

	}

	public CartesianChartModel getChart() {
		return chart;
	}

	public void setChart(CartesianChartModel chart) {
		this.chart = chart;
	}

	public List<Object[]> getLista() {
		return lista;
	}

	public void setLista(List<Object[]> lista) {
		this.lista = lista;
	}

	public Date getDataInicio() {
		return dataInicio;
	}

	public void setDataInicio(Date dataInicio) {
		this.dataInicio = dataInicio;
	}

	public Date getDataFim() {
		return dataFim;
	}

	public void setDataFim(Date dataFim) {
		this.dataFim = dataFim;
	}

}
